/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.blog.wordpress.entities.managedbeans;

import com.blog.wordpress.entities.RegisteredUser;
import com.blog.wordpress.sessionbeans.RegisteredUserFacadeLocal;
import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;

/**
 *
 * @author Breath
 */
@ManagedBean
@SessionScoped
public class LoginBean {

    RegisteredUser checkedUser = new RegisteredUser();
    String username;
    String password;
    @EJB
    RegisteredUserFacadeLocal regUserFa;
    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void retrieveUser() {
        this.setCheckedUser(regUserFa.findRegUserByUsername(username));
    }

    public RegisteredUser getCheckedUser() {
        return checkedUser;
    }

    public void setCheckedUser(RegisteredUser checkedUser) {
        this.checkedUser = checkedUser;
    }

    public RegisteredUserFacadeLocal getRegUserFa() {
        return regUserFa;
    }

    public void setRegUserFa(RegisteredUserFacadeLocal regUserFa) {
        this.regUserFa = regUserFa;
    }

    public String loginUser() {
        retrieveUser();
        if (checkedUser.getPassword().equals(password)) {
            return "showRegMenu";
        }
        return "showIndex";
    }
}
